# 类
"""
class 类名(继承的类):
....#初始化方法
....def __init__(self,param1):
........self.bianliang1 = 10 # 定义即初始化
........self.bianliang2 = param1 # 定义即初始化
....# 类中的方法
....def hello(self):
........print(self.bianliang2)
"""


# People类
# 属性：name、age、height
# 方法：eat() sleep() speak()

class People():
    # 初始化方法
    def __init__(self, name, age, height):
        self.name = name
        self.age = age
        self.height = height
        # Python中实际上没有严格意义上的封装，如果想要某个属性不被访问，那么可以在属性名前加上__
        self.__secret = "这是一个秘密"

    def eat(self):
        print("{} can eat".format(self.name))

    def sleep(self):
        print("{} can sleep".format(self.name))

    def speak(self, words):
        print("{} say: '{}'".format(self.name, words))


# 创建对象（实例化）
zhangSan = People("zhangSan", 24, 180)
print(zhangSan, type(zhangSan))
print(zhangSan.name)
print(zhangSan.age)
zhangSan.eat()
zhangSan.speak("hello World")
# print(zhangSan.secret)
# print(zhangSan.__secret)
# 如果真的想取出来 可以通过 _类名+属性名
# 一般不推荐这样去做
print(zhangSan._People__secret)

xiaoMing = People("xiaoMing", 22, 170)
print(xiaoMing, type(xiaoMing))


# 继承
class Student(People):
    def __init__(self, id, name, age, height, clazz):
        # 调用父类的初始化方法
        super(Student, self).__init__(name, age, height)
        # Student类特有的属性
        self.id = id
        self.clazz = clazz

    # 重新实现父类的方法
    def speak(self, words):
        print("I am a student,I say {}".format(words))


class Teacher(People):
    def __init__(self, id, name, age, height, clazz, phone):
        # 调用父类的初始化方法
        super(Teacher, self).__init__(name, age, height)
        # Student类特有的属性
        self.id = id
        self.clazz = clazz
        self.phone = phone

    # 重新实现父类的方法
    def speak(self, words):
        print("I am a teacher,I say {}".format(words))

    # 定义自己的方法
    def teaching(self):
        print("I can teaching Student")


stu1 = Student(1, "student1", 22, 190, "理科二班")
tea1 = Teacher("0001", "teacher1", 30, 180, "理科一班", "1888888888")

print(stu1.name)
print(stu1.age)
stu1.eat()

# 多态
stu1.speak("你好")
tea1.speak("hello")

